package demo3;

public class Text05 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println("hello thread...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("线程执行完成...");
        });

        System.out.println("启动之前查看线程是否存活：" + thread.isAlive());
        //启动线程
        thread.start();
        System.out.println("启动之后查看线程是否存活：" + thread.isAlive());
        //等待线程执行完成
        thread.join();
        //保证PCB已销毁
        Thread.sleep(1000);
        System.out.println("线程结束之后查看线程是否存活：" + thread.isAlive());
    }
}
